// pages/shop/order.js
const app = getApp();
var com = require("../../utils/util.js");
var car_id = '';
var product_id = '';
var desc = '';
Page({
  /**
   * 页面的初始数据
   */
  data: {
    list : {},
    total_price : 0,
    address : ''
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {
    if (e.s == 'details'){
      com.post('Api/Home/shop_order', { id: e.id }, "setContent", this);
    }else{
      com.post('Api/Home/car_order', { id: e.id }, "setContent", this);
    }
  },
  setContent: function (e) {
    car_id = e.car_id;
    product_id = e.product_id;
    this.setData({
      list: e.car,
      total_price: e.total_price
    });
  },
  /**
   * 调用微信原生地址
   */
  setAddress :function(){
    var self = this;
    wx.chooseAddress({
      success: function (res) {
        self.setData({
          address : res
        });
      }
    })
  },
  desc : function(e){
    desc = e.detail.value;
  },
  /**
   * 支付订单按钮
   */
  goPay : function(){
    if (!this.data.address){
      wx.showToast({
        title: '请选择地址！',
        icon: 'none',
        duration: 2000
      })
      return {};
    }
    com.post('Api/Home/go_pay', {
      product_id: product_id, 
      car_id: car_id,
      desc: desc, 
      uid: app.globalData.userInfo.uid,
      user: this.data.address.userName,
      phone: this.data.address.telNumber,
      address: this.data.address.provinceName + this.data.address.cityName + this.data.address.countyName + this.data.address.detailInfo,
    }, "wxPay", this);
  },
  /**
   * 调用原生微信支付
   */
  wxPay : function(){
    wx.requestPayment({
      'timeStamp': '',
      'nonceStr': '',
      'package': 'prepay_id=1',
      'signType': 'MD5',
      'paySign': '',
      'success': function (res) {
      },
      'fail': function (res) {
      }
    })
  }
})